home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2002 November / SGI IRIX Base Documentation 2002 November.iso / usr / share / catman / p_man / cat3c / mdbm.z / mdbm
Encoding:
Text File  |  2002-10-03  |  33.2 KB  |  529 lines

  1.  
  2.  
  3.  
  4. MMMMDDDDBBBBMMMM((((3333BBBB))))                                                              MMMMDDDDBBBBMMMM((((3333BBBB))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      mdbm: mdbm_open, mdbm_close, mdbm_fetch, mdbm_store, mdbm_delete,
  10.      mdbm_first, mdbm_firstkey, mdbm_next, mdbm_nextkey, mdbm_pre_split,
  11.      mdbm_set_alignment, mdbm_limit_size, mdbm_invalidate, mdbm_close_fd,
  12.      mdbm_sync, mdbm_lock, mdbm_unlock, mdbm_sethash- data base subroutines
  13.  
  14. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  15.      _cccc_cccc [_f_l_a_g ...] _f_i_l_e ...  _----_llll_mmmm_dddd_bbbb_mmmm [_l_i_b_r_a_r_y ...]
  16.  
  17.      ####iiiinnnncccclllluuuuddddeeee <<<<mmmmddddbbbbmmmm....hhhh>>>>
  18.  
  19.      MMMMDDDDBBBBMMMM ****mmmmddddbbbbmmmm____ooooppppeeeennnn((((ccccoooonnnnsssstttt cccchhhhaaaarrrr ****ffffiiiilllleeee,,,, iiiinnnntttt ffffllllaaaaggggssss,,,, mmmmooooddddeeee____tttt mmmmooooddddeeee,,,, iiiinnnntttt ppppaaaaggggeeeessssiiiizzzzeeee))));;;;
  20.  
  21.      vvvvooooiiiidddd mmmmddddbbbbmmmm____cccclllloooosssseeee((((MMMMDDDDBBBBMMMM ****ddddbbbb))));;;;
  22.  
  23.      ddddaaaattttuuuummmm mmmmddddbbbbmmmm____ffffeeeettttcccchhhh((((MMMMDDDDBBBBMMMM ****ddddbbbb,,,, kkkkvvvvppppaaaaiiiirrrr kkkkvvvv))));;;;
  24.  
  25.      iiiinnnntttt mmmmddddbbbbmmmm____ssssttttoooorrrreeee((((MMMMDDDDBBBBMMMM ****ddddbbbb,,,, ddddaaaattttuuuummmm kkkkeeeeyyyy,,,, ddddaaaattttuuuummmm ccccoooonnnntttteeeennnntttt,,,, iiiinnnntttt ffffllllaaaaggggssss))));;;;
  26.  
  27.      iiiinnnntttt mmmmddddbbbbmmmm____ddddeeeelllleeeetttteeee((((MMMMDDDDBBBBMMMM ****ddddbbbb,,,, ddddaaaattttuuuummmm kkkkeeeeyyyy))));;;;
  28.  
  29.      kkkkvvvvppppaaaaiiiirrrr mmmmddddbbbbmmmm____ffffiiiirrrrsssstttt((((MMMMDDDDBBBBMMMM ****ddddbbbb,,,, kkkkvvvvppppaaaaiiiirrrr kkkkvvvv))));;;;
  30.  
  31.      ddddaaaattttuuuummmm mmmmddddbbbbmmmm____ffffiiiirrrrssssttttkkkkeeeeyyyy((((MMMMDDDDBBBBMMMM ****ddddbbbb,,,, ddddaaaattttuuuummmm kkkkeeeeyyyy))));;;;
  32.  
  33.      kkkkvvvvppppaaaaiiiirrrr mmmmddddbbbbmmmm____nnnneeeexxxxtttt((((MMMMDDDDBBBBMMMM ****ddddbbbb,,,, kkkkvvvvppppaaaaiiiirrrr kkkkvvvv))));;;;
  34.  
  35.      ddddaaaattttuuuummmm mmmmddddbbbbmmmm____nnnneeeexxxxttttkkkkeeeeyyyy((((MMMMDDDDBBBBMMMM ****ddddbbbb,,,, ddddaaaattttuuuummmm kkkkeeeeyyyy))));;;;
  36.  
  37.      iiiinnnntttt mmmmddddbbbbmmmm____pppprrrreeee____sssspppplllliiiitttt((((MMMMDDDDBBBBMMMM ****ddddbbbb,,,, uuuuiiiinnnntttt66664444 ppppaaaaggggeeeessss,,,, iiiinnnntttt ffffllllaaaaggggssss))));;;;
  38.  
  39.      iiiinnnntttt mmmmddddbbbbmmmm____sssseeeetttt____aaaalllliiiiggggnnnnmmmmeeeennnntttt((((MMMMDDDDBBBBMMMM ****ddddbbbb,,,, iiiinnnntttt ppppoooowwwweeeerrrr))));;;;
  40.  
  41.      iiiinnnntttt mmmmddddbbbbmmmm____lllliiiimmmmiiiitttt____ssssiiiizzzzeeee((((MMMMDDDDBBBBMMMM ****ddddbbbb,,,, uuuuiiiinnnntttt66664444 ppppaaaaggggeeeessss,,,, iiiinnnntttt ((((****ffffuuuunnnncccc))))((((MMMMDDDDBBBBMMMM ****ddddbbbb,,,, ddddaaaattttuuuummmm
  42.      kkkkeeeeyyyy,,,, ddddaaaattttuuuummmm ccccoooonnnntttteeeennnntttt,,,, vvvvooooiiiidddd ****pppprrrriiiioooorrrriiiittttyyyy))))))));;;;
  43.  
  44.      iiiinnnntttt mmmmddddbbbbmmmm____iiiinnnnvvvvaaaalllliiiiddddaaaatttteeee((((MMMMDDDDBBBBMMMM ****ddddbbbb))));;;;
  45.  
  46.      vvvvooooiiiidddd mmmmddddbbbbmmmm____cccclllloooosssseeee____ffffdddd((((MMMMDDDDBBBBMMMM ****ddddbbbb))));;;;
  47.  
  48.      vvvvooooiiiidddd mmmmddddbbbbmmmm____ssssyyyynnnncccc((((MMMMDDDDBBBBMMMM ****ddddbbbb))));;;;
  49.  
  50.      iiiinnnntttt mmmmddddbbbbmmmm____lllloooocccckkkk((((MMMMDDDDBBBBMMMM ****ddddbbbb))));;;;
  51.  
  52.      iiiinnnntttt mmmmddddbbbbmmmm____uuuunnnnlllloooocccckkkk((((MMMMDDDDBBBBMMMM ****ddddbbbb))));;;;
  53.  
  54.      iiiinnnntttt mmmmddddbbbbmmmm____sssseeeetttthhhhaaaasssshhhh((((MMMMDDDDBBBBMMMM ****ddddbbbb,,,, iiiinnnntttt nnnnuuuummmmbbbbeeeerrrr))));;;;
  55.  
  56.      iiiinnnntttt mmmmddddbbbbmmmm____sssseeeetttt____cccchhhhaaaaiiiinnnn((((MMMMDDDDBBBBMMMM ****ddddbbbb))));;;;
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. MMMMDDDDBBBBMMMM((((3333BBBB))))                                                              MMMMDDDDBBBBMMMM((((3333BBBB))))
  71.  
  72.  
  73.  
  74.      ddddaaaattttuuuummmm mmmmddddbbbbmmmm____cccchhhhaaaaiiiinnnn____ffffeeeettttcccchhhh((((MMMMDDDDBBBBMMMM ****ddddbbbb,,,, kkkkvvvvppppaaaaiiiirrrr kkkkvvvv))));;;;
  75.  
  76.      kkkkvvvvppppaaaaiiiirrrr mmmmddddbbbbmmmm____cccchhhhaaaaiiiinnnn____ffffiiiirrrrsssstttt((((MMMMDDDDBBBBMMMM ****ddddbbbb,,,, kkkkvvvvppppaaaaiiiirrrr kkkkvvvv))));;;;
  77.  
  78.      kkkkvvvvppppaaaaiiiirrrr mmmmddddbbbbmmmm____cccchhhhaaaaiiiinnnn____nnnneeeexxxxtttt((((MMMMDDDDBBBBMMMM ****ddddbbbb,,,, kkkkvvvvppppaaaaiiiirrrr kkkkvvvv))));;;;
  79.  
  80.      iiiinnnntttt mmmmddddbbbbmmmm____cccchhhhaaaaiiiinnnn____ssssttttoooorrrreeee((((MMMMDDDDBBBBMMMM ****ddddbbbb,,,, ddddaaaattttuuuummmm kkkkeeeeyyyy,,,, ddddaaaattttuuuummmm vvvvaaaallll,,,, iiiinnnntttt ffffllllaaaaggggssss))));;;;
  81.  
  82.      iiiinnnntttt mmmmddddbbbbmmmm____cccchhhhaaaaiiiinnnn____ddddeeeelllleeeetttteeee((((MMMMDDDDBBBBMMMM ****ddddbbbb,,,, ddddaaaattttuuuummmm kkkkeeeeyyyy))));;;;
  83.  
  84.      ddddaaaattttuuuummmm mmmmddddbbbbmmmm____cccchhhhaaaaiiiinnnnPPPP____ffffeeeettttcccchhhh((((MMMMDDDDBBBBMMMM ****ddddbbbb,,,, kkkkvvvvppppaaaaiiiirrrr kkkkvvvv))));;;;
  85.  
  86.      kkkkvvvvppppaaaaiiiirrrr mmmmddddbbbbmmmm____cccchhhhaaaaiiiinnnnPPPP____ffffiiiirrrrsssstttt((((MMMMDDDDBBBBMMMM ****ddddbbbb,,,, kkkkvvvvppppaaaaiiiirrrr kkkkvvvv))));;;;
  87.  
  88.      kkkkvvvvppppaaaaiiiirrrr mmmmddddbbbbmmmm____cccchhhhaaaaiiiinnnnPPPP____nnnneeeexxxxtttt((((MMMMDDDDBBBBMMMM ****ddddbbbb,,,, kkkkvvvvppppaaaaiiiirrrr kkkkvvvv))));;;;
  89.  
  90.      iiiinnnntttt mmmmddddbbbbmmmm____cccchhhhaaaaiiiinnnnPPPP____ssssttttoooorrrreeee((((MMMMDDDDBBBBMMMM ****ddddbbbb,,,, ddddaaaattttuuuummmm kkkkeeeeyyyy,,,, ddddaaaattttuuuummmm vvvvaaaallll,,,, iiiinnnntttt ffffllllaaaaggggssss))));;;;
  91.  
  92.      iiiinnnntttt mmmmddddbbbbmmmm____cccchhhhaaaaiiiinnnnPPPP____ddddeeeelllleeeetttteeee((((MMMMDDDDBBBBMMMM ****ddddbbbb,,,, ddddaaaattttuuuummmm kkkkeeeeyyyy))));;;;
  93.  
  94.      iiiinnnntttt mmmmddddbbbbmmmm____sssseeeetttt____ddddaaaattttaaaaffffoooorrrrmmmmaaaatttt((((MMMMDDDDBBBBMMMM ****ddddbbbb,,,, uuuuiiiinnnntttt8888____tttt ddddaaaattttaaaaffffoooorrrrmmmmaaaatttt))));;;;
  95.  
  96.      ddddaaaattttuuuummmm mmmmddddbbbbmmmm____tttteeeesssstttt____aaaannnndddd____sssseeeetttt((((MMMMDDDDBBBBMMMM ****ddddbbbb,,,, kkkkvvvvppppaaaaiiiirrrr kkkkvvvv,,,, ddddaaaattttuuuummmm ssssttttoooorrrraaaaggggeeee))));;;;
  97.  
  98.      iiiinnnntttt mmmmddddbbbbmmmm____ccccoooommmmppppaaaarrrreeee____aaaannnndddd____sssswwwwaaaapppp((((MMMMDDDDBBBBMMMM ****ddddbbbb ,,,, ddddaaaattttuuuummmm kkkkeeeeyyyy,,,, ddddaaaattttuuuummmm oooollllddddvvvvaaaallll,,,, ddddaaaattttuuuummmm
  99.      nnnneeeewwwwvvvvaaaallll))));;;;
  100.  
  101.      iiiinnnntttt mmmmddddbbbbmmmm____ccccoooommmmppppaaaarrrreeee____aaaannnndddd____ddddeeeelllleeeetttteeee((((MMMMDDDDBBBBMMMM ****ddddbbbb,,,, ddddaaaattttuuuummmm kkkkeeeeyyyy,,,, ddddaaaattttuuuummmm oooollllddddvvvvaaaallll))));;;;
  102.  
  103.      iiiinnnntttt mmmmddddbbbbmmmm____aaaattttoooommmmiiiicccc____bbbbeeeeggggiiiinnnn((((MMMMDDDDBBBBMMMM ****ddddbbbb,,,, ddddaaaattttuuuummmm kkkkeeeeyyyy,,,, mmmmddddbbbbmmmm____ggggeeeennnnlllloooocccckkkk____tttt ****ssssttttoooorrrraaaaggggeeee))));;;;
  104.  
  105.      iiiinnnntttt mmmmddddbbbbmmmm____aaaattttoooommmmiiiicccc____eeeennnndddd((((MMMMDDDDBBBBMMMM ****ddddbbbb))));;;;
  106.  
  107.      uuuuiiiinnnntttt33332222 mmmmddddbbbbmmmm____cccchhhheeeecccckkkk((((cccchhhhaaaarrrr ****ffffiiiilllleeee,,,, uuuuiiiinnnntttt33332222 ffffllllaaaaggggssss))));;;;
  108.  
  109.      uuuuiiiinnnntttt33332222 mmmmddddbbbbmmmm____rrrreeeeppppaaaaiiiirrrr((((cccchhhhaaaarrrr ****ffffiiiilllleeee,,,, uuuuiiiinnnntttt33332222 ffffllllaaaaggggssss))));;;;
  110.  
  111.      iiiinnnntttt mmmmddddbbbbmmmm____bbbbyyyytttteeeessss____ppppeeeerrrr____ppppaaaaggggeeee((((MMMMDDDDBBBBMMMM ****ddddbbbb,,,, iiiinnnntttt ****ppppaaaaggggeeeessss))));;;;
  112.  
  113.      iiiinnnntttt mmmmddddbbbbmmmm____eeeelllleeeemmmm____ppppeeeerrrr____ppppaaaaggggeeee((((MMMMDDDDBBBBMMMM ****ddddbbbb,,,, iiiinnnntttt ****ppppaaaaggggeeeessss))));;;;
  114.  
  115. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  116.      The mdbm routines are used to store key/content pairs in a high
  117.      performance mapped hash file.  Mdbm databases use fixed size pages, but
  118.      the page size can be set on first open.  The database does per page
  119.      writer locking, and readers can detect and automaticly deal with writers.
  120.      This allows for scalable multiple simultaneous readers and writers to be
  121.      operating on the same mdbm file at the same time.
  122.  
  123.      Core functions are built into libc, the rest of them require linking with
  124.      libmdbm.  The functions in libc are:  _m_d_b_m__c_l_o_s_e, _m_d_b_m__c_l_o_s_e__f_d,
  125.      _m_d_b_m__f_e_t_c_h, _m_d_b_m__f_i_r_s_t, _m_d_b_m__f_i_r_s_t_k_e_y, _m_d_b_m__i_n_v_a_l_i_d_a_t_e, _m_d_b_m__n_e_x_t,
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. MMMMDDDDBBBBMMMM((((3333BBBB))))                                                              MMMMDDDDBBBBMMMM((((3333BBBB))))
  137.  
  138.  
  139.  
  140.      _m_d_b_m__n_e_x_t_k_e_y, _m_d_b_m__o_p_e_n, _m_d_b_m__s_e_t_h_a_s_h, _m_d_b_m__s_t_o_r_e, _m_d_b_m__s_y_n_c.
  141.  
  142.      Before a database can be accessed, it must be opened by _m_d_b_m__o_p_e_n.  This
  143.      will open and/or create the given file depending on the flags parameter
  144.      (see _o_p_e_n(_2)).  The pagesize parameter is a power of two between 8 (256
  145.      bytes) and 16 (65536 bytes).
  146.  
  147.      Once open, the data stored under a key is accessed by _m_d_b_m__f_e_t_c_h . The
  148.      kvpair argument must be setup as follows:
  149.  
  150.           typedef struct {
  151.                char *dptr;
  152.                int  dsize;
  153.           } datum;
  154.           typedef struct {
  155.                datum key;
  156.                datum val;
  157.           } kvpair;
  158.  
  159.      kv.key.dptr should point to the key, and kv.key.dsize should be set to
  160.      the length of the key.   kv.val.dptr should point to allocated memory,
  161.      which will be used to copy the result into.  kv.val.dsize should be the
  162.      size of the data.   If kv.val.dptr is null, the returned datum's dsize
  163.      field will bet set to the size of the value.   It is always sufficient to
  164.      allocate MDBM_PAGE_SIZE(db) bytes.
  165.  
  166.      A linear pass through all keys in a database may be made, in an
  167.      (apparently) random order, by use of _m_d_b_m__f_i_r_s_t_k_e_y (_m_d_b_m__f_i_r_s_t) and
  168.      _m_d_b_m__n_e_x_t_k_e_y(mdbm_next).  _M_d_b_m__f_i_r_s_t_k_e_y will return the first key
  169.      (key/content) in the database.  _M_d_b_m__n_e_x_t_k_e_y will return the next key
  170.      (key/content) in the database.  Space for both the key (and the value)
  171.      must be allocated as above.  The following code will traverse the
  172.      database retrieving every key and it's associated value.
  173.  
  174.           #include <mdbm.h>
  175.           #include <alloca.h>
  176.           int pagesize = MDBM_PAGE_SIZE(db);
  177.           char *key = alloca(pagesize);
  178.           char *val = alloca(pagesize);
  179.           for (kv.key.dptr = key , kv.key.dsize=pagesize,
  180.                kv.val.dptr = val, kv.val.dsize=pagesize,
  181.                kv.key = mdbm_first(db,kv);
  182.                kv.key.dptr != NULL;
  183.                kv.key.dptr = key , kv.key.dsize=pagesize,
  184.                kv.val.dptr = val, kv.val.dsize=pagesize,
  185.                kv.key = mdbm_next(db,kv))
  186.  
  187.      It is possible to use mdbm_firstkey and mdbm_nextkey to traverse the
  188.      database retriving only the keys.
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. MMMMDDDDBBBBMMMM((((3333BBBB))))                                                              MMMMDDDDBBBBMMMM((((3333BBBB))))
  203.  
  204.  
  205.  
  206.      Data is placed under a key by _m_d_b_m__s_t_o_r_e.  The _f_l_a_g_s field can be either
  207.      MMMMDDDDBBBBMMMM____IIIINNNNSSSSEEEERRRRTTTT or MMMMDDDDBBBBMMMM____RRRREEEEPPPPLLLLAAAACCCCEEEE.... MMMMDDDDBBBBMMMM____IIIINNNNSSSSEEEERRRRTTTT will only insert new entries
  208.      into the database and will not change an existing entry with the same
  209.      key.  MMMMDDDDBBBBMMMM____RRRREEEEPPPPLLLLAAAACCCCEEEE will replace an existing entry if it has the same key.
  210.      A key (and its associated contents) is deleted by _m_d_b_m__d_e_l_e_t_e.
  211.  
  212.      The mdbm_pre_split function can be used immediately after first open to
  213.      expand the directory to a specified size.  This helps to reduce the
  214.      number of pages that will be split when storing a large amount of data.
  215.      The pages parameter is a power of two for the depth of the tree. The
  216.      ppppaaaaggggeeeessss parameter is used to compute the number of pages in the database.
  217.      The formula for this is (2^pages).
  218.  
  219.      The contents may be forced to exist at a particular byte alignment using
  220.      mdbm_set_alignment so that you can store structures in the database.  The
  221.      parameter is a power of two between 0 and 3.  The only time this is
  222.      needed is when accessing non-copied data from a mdbm file.  This is not
  223.      safe unless all access are protected by calls to mdbm_lock and
  224.      mdbm_unlock, which is not recommended.
  225.  
  226.      The flags field can be 0 or MMMMDDDDBBBBMMMM____AAAALLLLLLLLOOOOCCCC____SSSSPPPPAAAACCCCEEEE.... MMMMDDDDBBBBMMMM____AAAALLLLLLLLOOOOCCCC____SSSSPPPPAAAACCCCEEEE attempts
  227.      to pre-allocate blocks to back the file if it is on a holely filesystem.
  228.  
  229.      On the fly memory checking of mdbm database can be requested by passing
  230.      the MMMMDDDDBBBBMMMM____MMMMEEEEMMMMCCCCHHHHEEEECCCCKKKK flag to _m_d_b_m__o_p_e_n.  If this is done during the creation
  231.      of a database, all subsequent opens of the database will inherit this
  232.      requirement.  This checking incurs a measurable performance penalty on
  233.      all operations.
  234.  
  235.      All mdbm functions can operate in a synchronous mode by passing the
  236.      OOOO____SSSSYYYYNNNNCCCC flag to mdbm_open.   All changes to the database will case a
  237.      _m_s_y_n_c(_2) of the appropriate section of the database to be performed.
  238.      This incurs a significant performance penalty on all _m_d_b_m__s_t_o_r_e
  239.      operations.
  240.  
  241.      The _m_d_b_m__l_i_m_i_t__s_i_z_e function can be used after first open to set a
  242.      maximum size limit on the database.  If supplied func is a function which
  243.      will be called with each item on a page if an item needs to be stored,
  244.      but there is no space.  The priority argument is an integer between 1 and
  245.      3 giving the pass number.  After three passes through the data, if space
  246.      has not been freed the store will fail.  The ppppaaaaggggeeeessss parameter is used to
  247.      compute the number of pages in the database. The formula for this is
  248.      (2^pages).
  249.  
  250.      _m_d_b_m__s_y_n_c simply forces the data to disk.  Since the database is a mapped
  251.      file most work is simply done in memory, and the state of the disk file
  252.      is only guaranteed after mdbm_sync.
  253.  
  254.      _M_d_b_m__i_n_v_a_l_i_d_a_t_e should be called to mark a mdbm file as invalid or
  255.      outdated.  This should be done before unlinking the mdbm file.  If this
  256.      is not done long running programs that may have the mdbm file open will
  257.      not detect that another process has remove the file.
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. MMMMDDDDBBBBMMMM((((3333BBBB))))                                                              MMMMDDDDBBBBMMMM((((3333BBBB))))
  269.  
  270.  
  271.  
  272.      If the database is a fixed size then the associated file descriptor can
  273.      be closed using mdbm_close_fd.  Otherwise the database will grow the file
  274.      and possibly remap it into memory as data is added.
  275.  
  276.      The routines _m_d_b_m__l_o_c_k and _m_d_b_m__u_n_l_o_c_k can be used to synchronize access
  277.      to an mdbm file.  These use a very unsophisticated spinlock in the shared
  278.      file to do the locking.  It is almost always unnecessary to use these
  279.      functions, and their use is highly discouraged.
  280.  
  281.      _m_d_b_m__s_e_t_h_a_s_h will set the has function of a database to number.   This
  282.      must be done immediately after creating the mdbm file.  The default hash
  283.      is 0.
  284.  
  285.      0000   32 bit CRC.
  286.  
  287.      1111   ejb's hsearch hash.  Not recommended.
  288.  
  289.      2222   Phong Vo's linear congruential hash.  Good for short keys.
  290.  
  291.      3333   Ozan Yigit's sdbm hash.  Good for long keys.
  292.  
  293.      4444   Torek's Duff device hash.  Good for ASCII key.  Bad for binary key.
  294.  
  295.      5555   Fowler/Noll/Vo prime hash.  Very good for keys under ~20 bytes.
  296.  
  297.      Under normal usage all mdbm databases have a limitation on the size of
  298.      key/value pairs that can be stored.  The available space for a single
  299.      key/value pair is (pagesize - 10) bytes,  where pagesize is determined by
  300.      raising 2 to the pagesize argument passed to _m_d_b_m__o_p_e_n when the database
  301.      is created.   Thus with pagesize set to 7 a page is 128 bytes long (2^7
  302.      bytes), and with pagesize set to 12 a page is 4kb (2^12 bytes).  If you
  303.      know the maximum size of key/value pair that you will be storing then you
  304.      should use this parameter to tune the mdbm database.   If you dont know
  305.      the maxium size of a key/value pair, then you should use the mdbm_chain
  306.      interface described below.  There is always a slight performance penalty
  307.      when using the mdbm_chain interface.
  308.  
  309.      There are a number of functions that allow storage of unlimited size
  310.      values via mdbm.   These are the the _m_d_b_m__c_h_a_i_n_* functions.   Before any
  311.      keys are stored in an mdbm database, use the _m_d_b_m__s_e_t__c_h_a_i_n routine to
  312.      enable this feature in a given database.   Use _m_d_b_m__o_p_e_n and _m_d_b_m__c_l_o_s_e
  313.      with a mdbm file that supports chaining. It is impossible to get a
  314.      pointer to the copy of the data in the database by passing a NULL value.
  315.      In this case the val.dsize field will be set to the size needed to
  316.      retrieve the data.
  317.  
  318.      _m_d_b_m__c_h_a_i_n__f_e_t_c_h, _m_d_b_m__c_h_a_i_n__s_t_o_r_e, and _m_d_b_m__c_h_a_i_n__d_e_l_e_t_e behave similar
  319.      to the non chaining versions. _m_d_b_m__c_h_a_i_n__f_i_r_s_t and _m_d_b_m__c_h_a_i_n__n_e_x_t do NOT
  320.      return the value, and kv.val should have dptr set to NULL with dsize set
  321.      to 0.  On return dsize will be set to the size needed to copyout the
  322.      data.
  323.  
  324.  
  325.  
  326.  
  327.                                                                         PPPPaaaaggggeeee 5555
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. MMMMDDDDBBBBMMMM((((3333BBBB))))                                                              MMMMDDDDBBBBMMMM((((3333BBBB))))
  335.  
  336.  
  337.  
  338.      When chaining is enabled, the first character of a key may not start with
  339.      a NULL byte unless the MMMMDDDDBBBBMMMM____CCCCHHHHAAAAIIIINNNN____NNNNUUUULLLLLLLL flag is passed to the
  340.      _m_d_b_m__c_h_a_i_n__s_t_o_r_e function.   All keys starting with NULL are ignored
  341.      during _m_d_b_m__c_h_a_i_n__f_i_r_s_t and _m_d_b_m__c_h_a_i_n__n_e_x_t.
  342.  
  343.      There are a number of functions that will do the basic mdbm operations on
  344.      mdbm files correctly supporting chaining if enabled for a given database.
  345.      These are the _m_d_b_m__c_h_a_i_n_P_* functions.   They can be used in place of the
  346.      associated mdbm_* or mdbm_chain_* functions.
  347.  
  348.      The _m_d_b_m__s_e_t__d_a_t_a_f_o_r_m_a_t function allows a program to set a program
  349.      specific database format identified that can be accessed with the
  350.      (uint8_t) mmmmddddbbbbmmmm____ddddaaaattttaaaaffffoooorrrrmmmmaaaatttt ((((MMMMDDDDBBBBMMMM ****ddddbbbb)))) function.  This dataformat is set to
  351.      0 by default, and is only used by programs makeing explict use of this
  352.      feature.
  353.  
  354.      The _m_d_b_m__f_e_t_c_h, _m_d_b_m__f_i_r_s_t, _m_d_b_m__f_i_r_s_t_k_e_y, _m_d_b_m__n_e_x_t, _m_d_b_m__n_e_x_t_k_e_y, and
  355.      _m_d_b_m__s_t_o_r_e functions as well as the mdbm_chain_* and mdbm_chainP_*
  356.      counterparts are atomic in nature.   There are a number of complex atomic
  357.      operators that can fetch and store keys in an atomic manner. The
  358.      _m_d_b_m__t_e_s_t__a_n_d__s_e_t function takes a new key/value pair, and sets key to
  359.      the value.  The current value of key will be returned in the storage
  360.      provided. The _m_d_b_m__c_o_m_p_a_r_e__a_n_d__s_w_a_p function takes a key and compares the
  361.      current value it is associated with with oldval.   If they are exactly
  362.      the same key will be set to newval.  The _m_d_b_m__c_o_m_p_a_r_e__a_n_d__d_e_l_e_t_e is
  363.      similar, but if the current value is oldval, the key will be delete.
  364.      Atomic creates can be done with mdbm_store with the MDBM_INSERT flag set.
  365.  
  366.      The _m_d_b_m__a_t_o_m_i_c__b_e_g_i_n and _m_d_b_m__a_t_o_m_i_c__e_n_d functions allow complex atomic
  367.      functions to be built. _m_d_b_m__a_t_o_m_i_c__b_e_g_i_n may be called multiple times for
  368.      multiple keys.  Then use the standard mdbm functions to access or modify
  369.      these keys.   Then call _m_d_b_m__a_t_o_m_i_c__e_n_d.  Only one call to
  370.      mdbm_atomic_end is required.   The third argument is the address of
  371.      storage large enough to hold a mdbm_genlock_t.   It is suggested that
  372.      this is the address of a variable on the stack.   It is not safe to next
  373.      mdbm_atomic operations.   Do NOT call mdbm_compare_and_swap between
  374.      _m_d_b_m__a_t_o_m_i_c__b_e_g_i_n and _m_d_b_m__a_t_o_m_i_c__e_n_d.
  375.  
  376.      Use of atomic operators increases the possibility that a program will
  377.      crash while holding a database lock.  If this happens a database can be
  378.      checked and repaired.   It is NNNNOOOOTTTT safe to repair a database while any
  379.      other processes or threads are accessing it.   But it is safe to check a
  380.      database.   The _m_d_b_m__c_h_e_c_k and _m_d_b_m__r_e_p_a_i_r functions work on a mdbm file
  381.      and take a set of flags telling them what to check or try to repair.  The
  382.      functions return a set of flags telling what checked out bad, or was
  383.      unrepairable.  The output of _m_d_b_m__c_h_e_c_k can be used as the input flags to
  384.      mdbm_repair.   The macro _M_D_B_M__C_H_E_C_K__A_L_L requests that all possible error
  385.      cases are check.
  386.  
  387.      _m_d_b_m__b_y_t_e_s__p_e_r__p_a_g_e, and _m_d_b_m__e_l_e_m__p_e_r__p_a_g_e take a pointer to an array of
  388.      length MMMMDDDDBBBBMMMM____NNNNUUUUMMMMBBBBEEEERRRR____PPPPAAAAGGGGEEEESSSS (MDBM *db) which will be filled with the
  389.      appropriate statistic.
  390.  
  391.  
  392.  
  393.                                                                         PPPPaaaaggggeeee 6666
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400. MMMMDDDDBBBBMMMM((((3333BBBB))))                                                              MMMMDDDDBBBBMMMM((((3333BBBB))))
  401.  
  402.  
  403.  
  404. DDDDIIIIAAAAGGGGNNNNOOOOSSSSTTTTIIIICCCCSSSS
  405.      All functions that return an _i_n_t indicate errors with negative values.  A
  406.      zero return indicates ok.  Routines that return a _d_a_t_u_m indicate errors
  407.      with a null (0) _d_p_t_r. If _m_d_b_m__s_t_o_r_e called with a _f_l_a_g_s value of
  408.      MMMMDDDDBBBBMMMM____IIIINNNNSSSSEEEERRRRTTTT finds an existing entry with the same key it returns 1.
  409.  
  410.      If there is an error during an mdbm call, the global error value eeeerrrrrrrrnnnnoooo
  411.      will be set.  The following errors will will be set.
  412.  
  413.      EEEEBBBBAAAADDDDFFFF     During the open or access of a database the file version was
  414.                not valid, or internal structures are invalid.  This implies
  415.                that the mdbm file is corrupted.
  416.  
  417.      EEEEBBBBAAAADDDDFFFFDDDD    During the open of a database the file magic number was not
  418.                valid.  File is not a recognised mdbm file.  EEEEBBBBUUUUSSSSYYYY During a
  419.                _m_d_b_m__c_o_m_p_a_r_e__a_n_d__s_w_a_p or _m_d_b_m__c_o_m_p_a_r_e__a_n_d__d_e_l_e_t_e the current
  420.                value in the database is not oldval.
  421.  
  422.      EEEEDDDDEEEEAAAADDDDLLLLKKKK   A accessed page was locked, and after a number of attempts did
  423.                not become unlocked.
  424.  
  425.      EEEEDDDDEEEEAAAADDDDLLLLOOOOCCCCKKKK During a page lock, a livelock was detected and held locks may
  426.                have been broken.
  427.  
  428.      EEEEEEEEXXXXIIIISSSSTTTT    A store with the MMMMDDDDBBBBMMMM____IIIINNNNSSSSEEEERRRRTTTT flag set failed since the key
  429.                already exists.  A function that changes header parameters is
  430.                attempted when there is data already stored in the database.
  431.  
  432.      EEEEIIIINNNNVVVVAAAALLLL    An invlid argument was passed.
  433.  
  434.      EEEENNNNOOOOEEEEXXXXIIIISSSSTTTT  The requested key does not exist in the database.
  435.  
  436.      EEEENNNNOOOOLLLLCCCCKKKK    A request to find the lock on a page that should be locked by
  437.                the current process failed.
  438.  
  439.      EEEENNNNOOOOMMMMEEEEMMMM    Internal allocation of memory failed.  The only allocation that
  440.                is performed is the MDBM structure that is returned by
  441.                _m_d_b_m__o_p_e_n which is freed by _m_d_b_m__c_l_o_s_e.
  442.  
  443.      EEEENNNNOOOOSSSSPPPPCCCC    There is insufficient space in the database to store the
  444.                requested key or if no shake function is defined for a fixed
  445.                size database.
  446.  
  447.      EEEEPPPPEEEERRRRMMMM     Permission to perform a write to the mdbm file is denied.
  448.  
  449.      EEEESSSSTTTTAAAALLLLEEEE    The mdbm file has been invalidated.  It is suggested that an
  450.                attempt to re-open the database should be made, since a writing
  451.                process may invalidate an mdbm file, and create a new one with
  452.                the same filename.
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.                                                                         PPPPaaaaggggeeee 7777
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466. MMMMDDDDBBBBMMMM((((3333BBBB))))                                                              MMMMDDDDBBBBMMMM((((3333BBBB))))
  467.  
  468.  
  469.  
  470. CCCCAAAAVVVVEEEEAAAATTTTSSSS
  471.      The file is designed to contain holes in files.  The EFS file system does
  472.      not implement holes, so the file will frequently be significantly larger
  473.      than the actual content.
  474.  
  475.      The sum of the sizes of a key/content pair must not exceed the internal
  476.      block size (defaults to 4096 bytes).  Moreover all key/content pairs that
  477.      hash together must fit on a single page.  The page size can be set to a
  478.      maximum of 64KB on first open.  _M_d_b_m__s_t_o_r_e will return an error in the
  479.      event that a disk block fills with inseparable data.
  480.  
  481.      The order of keys presented by _m_d_b_m__f_i_r_s_t, _m_d_b_m__f_i_r_s_t_k_e_y, _m_d_b_m__n_e_x_t and
  482.      _m_d_b_m__n_e_x_t_k_e_y depends on a hashing function and the order they were stored
  483.      in the database, not on anything interesting.
  484.  
  485.      _M_d_b_m__d_e_l_e_t_e does not physically reclaim file space, although it does make
  486.      it available for reuse.
  487.  
  488.      It is incorrect to truncate a mdbm database.   The correct procedure is
  489.      to create a new database, open the old database, rename the new database
  490.      on top of the old database, invalidate the old database, unlink the old
  491.      database.
  492.  
  493.  
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.                                                                         PPPPaaaaggggeeee 8888
  526.  
  527.  
  528.  
  529.